* Lohaus & Stapel
* "Who commits to regional human rights treaties? Reputational benefits, sovereignty costs, and regional dynamics"
* Journal of Human Rights

*** OVERVIEW OF DO-FILE
* 1) user-written Stata packages used for analysis, tables and figures
* 2) read in data
* 3) data preparation for analysis
* 4) descriptive statistics - data analysis (Figures 1,2 and 4)
* 5) inferential statistics - data analysis (Figure 3 and Table 2 as presented in the article)
* 6) summary statistics (Table A2)
* 7) robustness checks (Tables A3-A7)



*** USER-WRITTEN STATA PACKAGES USED FOR ANALYSIS, TABLES AND FIGURES ***

*st0085_2: making regression tables from stored estimates, see Jann 2005
ssc install estout, replace
*blindschemes: blindschemes is a package containing four Stata figure schemes, see Bischof 2015 
ssc install blindschemes



*** READ IN DATA ***
clear 
import delimited "ratif_dyad.csv", encoding(UTF-8)



*** DATA PREPARATION FOR ANALYSIS ***

* Drop observations for treaties adopted after 2009, because we do not have enough time-series data to draw conclusions
drop if treatyyear > 2009

* logartihmize GDP data
generate lgdp = log(gdp)

* re-scale alternative specification of the democracy score (vdem_polyarchy) data to a scale between 0 and 10 (original scale is 0 to 1)
* for easier intepretation of results
gen vdem_polyarchy10= vdem_polyarchy*10

* Count the years until the respective treaty was signed, accounting for the fact that some countries joined later and thus could not sign earlier
generate years = year - treatyyear + (treatyyear - joinyear)
replace years = years - (treatyyear - joinyear) if treatyyear > joinyear

* drop irrelevant years
drop if years < 0
drop if years == .



*** DESCRIPTIVE STATISTICS - DATA ANALYSIS ***

* Please note that the following figures have been created using the software R
* Figure 1: Ratification of human rights agreements in the OAS and OAU/AU
* Figure 2: Average number of years until treaty ratification
* Figure 4: Number of treaties ratified before and after episodes of democratization 

* Please consult the respective R scripts which are stored in the same repository



*** INFERENTIAL STATISTICS - DATA ANALYSIS ***

*** Models presented in the paper (Figure 3, Table 2) ***

* declare data to be survival-time data
stset years, id(id2) failure(ratif) origin(time -1)


** Figure 3
* name: Results of the event history analysis
* the two main models produce estimates for six independent variables for each of the two RIOs (OAS (model 1) and OAU/AU (model 2))

stcox fh_ipolity2 democratization3 regratifs highcost_court lgdp commonlaw  if rio=="OAS", vce(cluster country) 
estimates store A
stcox fh_ipolity2 democratization3 regratifs highcost_court lgdp commonlaw  if rio=="AU", vce(cluster country)
estimates store B

set scheme plotplain
coefplot (A, label(OAS) symbol(circle)) (B, label(OAU/AU) symbol (square)), label(Core model) xline(1, lcolor(gray)) order(fh_ipolity2 democratization3 regratifs highcost_court lgdp commonlaw) mlabel format(%9.3g) mlabposition(2) mlabgap(*2) xlabel(#8) legend(cols(2) position(6)) subtitle(, color(white) bcolor(black) bmargin(top_bottom)) coeflabels(fh_ipolity2 = "Democracy" democratization3="Democratization" regratifs="Neighborhood ratification" highcost_court="High sovereignty costs" lgdp ="GDP (USD, logged)" commonlaw="Common law") eform



** Table 2
* name: Results of the event history analysis for the main model and extended model 
* Models 1 and 2 reproduce the main models (see above)
* Models 3 and 4 add three additional variables frequently discussed in the literature on commitment:
* change of government regardless of regime type (newlead2), thematically similar UN event in the previous three years (un_meeting), and ongoing domestic conflict (ucdp_type3)

eststo M1: stcox fh_ipolity2 democratization3 regratifs highcost_court lgdp commonlaw  if rio=="OAS", vce(cluster country) 
eststo M2: stcox fh_ipolity2 democratization3 regratifs highcost_court lgdp commonlaw  if rio=="AU", vce(cluster country)
eststo M3: stcox fh_ipolity2 democratization3 regratifs lgdp highcost_court commonlaw newlead2 un_meeting ucdp_type3 if rio=="OAS", vce(cluster country)
eststo M4: stcox fh_ipolity2 democratization3 regratifs lgdp highcost_court commonlaw newlead2 un_meeting ucdp_type3 if rio=="AU", vce(cluster country)
esttab M1 M2 M3 M4 using "Table 2 - Results of the event history analysis for the main model and extended model.csv", eform se b(3) bic replace



** Online appendix
** see Journal of Human Rights Harvard Dataverse page


*** SUMMARY STATISTICS ***

** Table A2
* name: summary statistics
sum ratif fh_ipolity2 democratization3 regratifs highcost_court lgdp commonlaw newlead2 un_meeting ucdp_type3 if _st ==1



*** ROBUSTNESS CHECKS ***


** Table A3
* name: Extended model for the OAS without the 1994 treaty on women's rights
* the timing of UN events strongly correlates with regional women's rights treaty ratification 
* but the timing of UN events is no longer statistically significant if the 1994 OAS women's rights treaty is excluded from the analysis

eststo M1: stcox fh_ipolity2 democratization3 regratifs lgdp highcost_court commonlaw newlead2 un_meeting ucdp_type3 if rio=="OAS" & treaty!="oas_1994a", vce(cluster country)
esttab M1 using "Table A3 - Extended model for the OAS without the 1994 treaty on women's rights.csv", eform se b(3) bic replace



** Table A4
* name: Models with dummy variables for each country or treaty 
* to account for unobserved heterogeneity for the main and the extended models
* we add a dummy variable for each country to focus only on the covariates that vary between country-treaty dyads but not between countries (Models 1-4)
* we add a dummy variable for each treaty to probe the robustness of the country-specific covariates (Models 5-8)

* country fixed effects
* country fixed effects (main model)
eststo M1: stcox regratifs highcost_court i.ccodecow if rio=="OAS"
eststo M2: stcox regratifs highcost_court i.ccodecow if rio=="AU"
* country fixed effects (extended model)
eststo M3: stcox regratifs highcost_court un_meeting  i.ccodecow if rio=="OAS"
eststo M4: stcox regratifs highcost_court un_meeting  i.ccodecow if rio=="AU"

* treaty fixed effects
* because the treaty variable is a string variable which cannot be included to estimate fixed effects, we create a new variable 'treaty number' (treatyno)
generate treatyno = .
replace treatyno = 1 if treaty=="oas_1969"
replace treatyno = 2 if treaty=="oas_1969court"
replace treatyno = 3 if treaty=="oas_1985a"
replace treatyno = 4 if treaty=="oas_1988"
replace treatyno = 5 if treaty=="oas_1990"
replace treatyno = 6 if treaty=="oas_1994a"
replace treatyno = 7 if treaty=="oas_1994b"
replace treatyno = 8 if treaty=="oas_1999"
replace treatyno = 9 if treaty=="au_1969"
replace treatyno = 10 if treaty=="au_1976"
replace treatyno = 11 if treaty=="au_1981"
replace treatyno = 12 if treaty=="au_1990"
replace treatyno = 13 if treaty=="au_1998"
replace treatyno = 14 if treaty=="au_2003"
replace treatyno = 15 if treaty=="au_2006"
replace treatyno = 16 if treaty=="au_2008"
* treaty fixed effects (main model)
eststo M5: stcox fh_ipolity2 democratization3 regratifs lgdp commonlaw i.treatyno if rio=="OAS", vce(cluster country)
eststo M6: stcox fh_ipolity2 democratization3 regratifs lgdp commonlaw i.treatyno if rio=="AU", vce(cluster country)
* treaty fixed effects (extended model)
eststo M7: stcox fh_ipolity2 democratization3 regratifs lgdp commonlaw newlead2 ucdp_type3 i.treatyno if rio=="OAS", 
eststo M8: stcox fh_ipolity2 democratization3 regratifs lgdp commonlaw newlead2 ucdp_type3 i.treatyno if rio=="AU", vce(cluster country)

* note: in Table A4 in the online appendix, we do not show the coeffficients for the country and treaty dummies
esttab M1 M2 M3 M4 M5 M6 M7 M8 using "Table A4 - Models with dummy variables for each country or treaty.csv", eform se b(3) bic replace



** Table A5
* name: Models with shared frailty at the country or the treaty level
* to account for unobserved heterogeneity, we run shared frailty models
* it is assumed that the hazard ratios among cases involving the same country are linked (akin to  "shared" frailty of patients treated in the same hospital)

* shared frailty models - country
eststo M1: stcox fh_ipolity2 democratization3 regratifs highcost_court lgdp commonlaw  if rio=="OAS",  frailty(gamma) shared(country) forceshared
eststo M2: stcox fh_ipolity2 democratization3 regratifs highcost_court lgdp commonlaw  if rio=="AU", frailty(gamma) shared(country) forceshared
eststo M3: stcox fh_ipolity2 democratization3 regratifs lgdp highcost_court commonlaw newlead2 un_meeting ucdp_type3 if rio=="OAS", frailty(gamma) shared(country) forceshared
eststo M4: stcox fh_ipolity2 democratization3 regratifs lgdp highcost_court commonlaw newlead2 un_meeting ucdp_type3 if rio=="AU", frailty(gamma) shared(country) forceshared

* shared frailty models - treaty
eststo M5: stcox fh_ipolity2 democratization3 regratifs highcost_court lgdp commonlaw  if rio=="OAS",  frailty(gamma) shared(treaty) forceshared
eststo M6: stcox fh_ipolity2 democratization3 regratifs highcost_court lgdp commonlaw  if rio=="AU", frailty(gamma) shared(treaty) forceshared
eststo M7: stcox fh_ipolity2 democratization3 regratifs lgdp highcost_court commonlaw newlead2 un_meeting ucdp_type3 if rio=="OAS", frailty(gamma) shared(treaty) forceshared
eststo M8: stcox fh_ipolity2 democratization3 regratifs lgdp highcost_court commonlaw newlead2 un_meeting ucdp_type3 if rio=="AU", frailty(gamma) shared(treaty) forceshared

esttab M1 M2 M3 M4 M5 M6 M7 M8 using "Table A5 - Models with shared frailty at the country or the treaty level.csv", eform se pr2 b(3) aic bic replace



** Table A6
* name: Models with alternative democracy and democratization variables
* to make sure that limited data availability of the Quality of Government (QoG) imputed Freedom House and Polity IV score does not distort the results
* we use V-Dem's Electoral Democracy Index to run the models again: democracy score (vdem_polyarchy10) and democratization episode (newdem3)

eststo M1: stcox vdem_polyarchy10 newdem3 regratifs highcost_court lgdp commonlaw  if rio=="OAS", vce(cluster country) 
eststo M2: stcox vdem_polyarchy10 newdem3 regratifs highcost_court lgdp commonlaw  if rio=="AU", vce(cluster country)
eststo M3: stcox vdem_polyarchy10 newdem3 regratifs lgdp highcost_court commonlaw newlead2 un_meeting ucdp_type3 if rio=="OAS", vce(cluster country)
eststo M4: stcox vdem_polyarchy10 newdem3 regratifs lgdp highcost_court commonlaw newlead2 un_meeting ucdp_type3 if rio=="AU", vce(cluster country)
esttab M1 M2 M3 M4 using "Table A6 - Models with alternative democracy and democratization variables.csv", eform se b(3) bic replace



** TABLE A7
* name: Negative binomial regression of ratifications per treaty
* one of the anonymous reviewers suggested a count poisson regression of the number of ratifiers per treaty per year 
* to probe the effect of treaty-related sovereignty costs
* because the data is over-dispersed, we use negative binomial regression models

* this analysis requires a different data structure, please use the following CSV data file
clear
import delimited "C:\Users\soere\Dropbox\regcom-stata\ratifcounts.csv"

* account for panel structure
generate treatyno = .
replace treatyno = 1 if treaty=="oas_1969"
replace treatyno = 2 if treaty=="oas_1969court"
replace treatyno = 3 if treaty=="oas_1985a"
replace treatyno = 4 if treaty=="oas_1988"
replace treatyno = 5 if treaty=="oas_1990"
replace treatyno = 6 if treaty=="oas_1994a"
replace treatyno = 7 if treaty=="oas_1994b"
replace treatyno = 8 if treaty=="oas_1999"
replace treatyno = 9 if treaty=="au_1969"
replace treatyno = 10 if treaty=="au_1976"
replace treatyno = 11 if treaty=="au_1981"
replace treatyno = 12 if treaty=="au_1990"
replace treatyno = 13 if treaty=="au_1998"
replace treatyno = 14 if treaty=="au_2003"
replace treatyno = 15 if treaty=="au_2006"
replace treatyno = 16 if treaty=="au_2008"
drop if treatyno==.

* declare data to be panel
xtset treatyno year 

* negative binomial regression
eststo M1: xtnbreg ratifs_cum audummy##costdummy if year==2019
esttab M1 using "Table A7 - Negative binomial regression of ratifications per treaty.csv", se b(3) bic replace

